package com.glb.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Subset4 {
  public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        List<List<Integer>> subsets = subsets(nums);
        for (List<Integer> subset : subsets) {
            System.out.println(subset);
        }
    }

  private static List<List<Integer>> subsets(int[] nums){
    List<List<Integer>> result = new ArrayList<>();
    List<Integer> subset0 = new ArrayList<>();
    result.add(subset0);

    for (int num : nums) {
      int size = result.size();
      for (int i = 0; i < size; i++) {
        List<Integer> subset = new ArrayList<>(result.get(i));
        subset.add(num);
        result.add(subset);
      }
    }

    return result;
  }
}
